package activity;
import java.io.IOException;
import java.util.Date;

import activity.PMF;

import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.jdo.PersistenceManager;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;



	public class AddActServlet_d extends HttpServlet {
		private static final long serialVersionUID = 1L;
		private static final String nextJSP = "/activityN.jsp";

		public void doGet(HttpServletRequest request, HttpServletResponse response)
	            throws IOException, ServletException {

			request.setCharacterEncoding("utf-8");
			UserService userService = UserServiceFactory.getUserService();
	        User user_d = userService.getCurrentUser();
	        Date actStart_d = new Date();
			//String productID = request.getParameter("PNO");
	        
			String actShop_d = request.getParameter("actShop_d");
			String actName_d = request.getParameter("actName_d");
			String actPoint_D = request.getParameter("actPoint_d");
			String actContent_d = request.getParameter("actContent_d");
			String actEnd_d = request.getParameter("actEnd_d");
			String actShop_s = request.getParameter("actShop_s");
			String actName_s = request.getParameter("actName_s");
			String actPoint_S = request.getParameter("actPoint_s");
					
			
			
			int actPoint_d = 0;
			int actPoint_s = 0;
			

	   	
			try {
								
				
				actPoint_d = Integer.parseInt(actPoint_D);
				actPoint_s = Integer.parseInt(actPoint_S);
				
			}
			catch (NumberFormatException e){
				//implementation is needed
			}
			PersistenceManager pm = PMF.get().getPersistenceManager();
			try{
				Activity_demand act = new Activity_demand(actShop_d,actPoint_d,actName_d,actEnd_d,actStart_d,actContent_d,user_d,actShop_s,actName_s,actPoint_s);				
				pm.makePersistent(act);
				
			} finally {
			    pm.close();
			}
			
			response.sendRedirect(nextJSP);
			
	    }
		public void doPost(HttpServletRequest request, HttpServletResponse response) 
				throws IOException, ServletException{
			doGet(request, response);
		}
	}
